<script setup lang="ts">
import { AlipayCircleFilled, LockOutlined, MobileOutlined, TaobaoCircleFilled, UserOutlined, WeiboCircleFilled } from '@ant-design/icons-vue'
import {reactive, shallowRef} from "vue";
import GlobalLayoutFooter from '@/layouts/components/global-footer/index.vue'
import FooterLinks from "~/components/footer-links.vue";

const loginModel = reactive({
  username: undefined,
  password: undefined,
  mobile: undefined,
  code: undefined,
  type: 'account',
  remember: true,
})
const errorAlert = shallowRef(false)
const codeLoading = shallowRef(false)
const submitLoading = shallowRef(false)
</script>

<template>
  <div class="login-container">
    <div class="login-content flex-center">
      <div class="login-main rounded">
        <!--    登录框顶部    -->
        <div class="flex-between h-15 px-4 mb-[2px]">
          <div class="flex-end">
            <div class="login-logo">
              <img w-full h-full object-cover src="/favicon.png">
            </div>
            <div class="login-title">
              锦衣卫
            </div>
            <div class="login-desc">
              锦衣卫后台管理系统
            </div>
          </div>
        </div>
        <a-divider m-0 />
        <!--   登录框主题     -->
        <div class="box-border flex min-h-[520px]">
          <!-- 登录框左侧 -->
          <div class="login-main-left min-h-[520px] flex-center  bg-[var(--bg-color-container)]">
            <img src="@/assets/images/login-left.png" class="h-5/6 w-5/6">
          </div>
          <a-divider m-0 type="vertical" class="login-divider  min-h-[520px]" />
          <!-- 登录框右侧 -->
          <div class="login-main-right px-5 w-[335px] flex-center flex-col relative z-11">
            <div class="text-center py-6 text-2xl">
              欢迎使用本系统
            </div>
            <a-form ref="formRef" :model="loginModel">
              <a-tabs v-model:active-key="loginModel.type" centered>
                <a-tab-pane key="account" tab="账号密码登录" />
                <a-tab-pane key="mobile" tab="手机号登录" />
              </a-tabs>
              <!-- 判断是否存在error -->
              <a-alert
                  v-if="errorAlert && loginModel.type === 'account'" mb-24px
                  message="t('pages.login.accountLogin.errorMessage')" type="error" show-icon
              />
              <a-alert
                  v-if="errorAlert && loginModel.type === 'mobile'" mb-24px
                  message="t('pages.login.phoneLogin.errorMessage')" type="error" show-icon
              />

              <template v-if="loginModel.type === 'account'">
                <a-form-item name="username" :rules="[{ required: true, message: '' }]">
                  <a-input
                      v-model:value="loginModel.username" allow-clear
                      autocomplete="off"
                      placeholder="用户名 admin or user" size="large" @press-enter=""
                  >
                    <template #prefix>
                      <UserOutlined />
                    </template>
                  </a-input>
                </a-form-item>
                <a-form-item name="password" :rules="[{ required: true, message: '' }]">
                  <a-input-password
                      v-model:value="loginModel.password" allow-clear
                      placeholder="密码 admin" size="large" @press-enter=""
                  >
                    <template #prefix>
                      <LockOutlined />
                    </template>
                  </a-input-password>
                </a-form-item>
              </template>
              <template v-if="loginModel.type === 'mobile'">
                <a-form-item
                    name="mobile" :rules="[
                    { required: true, message: '' },
                    {
                      pattern: /^(86)?1([38][0-9]|4[579]|5[0-35-9]|6[6]|7[0135678]|9[89])[0-9]{8}$/,
                      message: '',
                    },
                  ]"
                >
                  <a-input
                      v-model:value="loginModel.mobile" allow-clear
                      placeholder="请输入手机号!" size="large" @press-enter=""
                  >
                    <template #prefix>
                      <MobileOutlined />
                    </template>
                  </a-input>
                </a-form-item>
                <a-form-item name="code" :rules="[{ required: true, message: '' }]">
                  <div flex items-center>
                    <a-input
                        v-model:value="loginModel.code"
                        style="flex: 1 1 0%; transition: width 0.3s ease 0s; margin-right: 8px;" allow-clear
                        placeholder="请输入验证码!" size="large" @press-enter=""
                    >
                      <template #prefix>
                        <LockOutlined />
                      </template>
                    </a-input>
                    <a-button :loading="codeLoading" disabled="" size="large" @click="">
                      <template v-if="!true">
                        {{ '获取验证码' }}
                      </template>
                      <template v-else>
                        {{ 50 }} {{ '秒后重试' }}
                      </template>
                    </a-button>
                  </div>
                </a-form-item>
              </template>
              <div class="mb-24px flex-between">
                <a-checkbox v-model:checked="loginModel.remember">
                  {{ '自动登录' }}
                </a-checkbox>
                <a>{{ '忘记密码?' }}</a>
              </div>
              <a-button type="primary" block :loading="submitLoading" size="large" @click="">
                {{ '登录' }}
              </a-button>
            </a-form>
            <a-divider>
              <span class="text-slate-500">{{ '其他登录方式' }}</span>
            </a-divider>
            <div class="login-other">
              <AlipayCircleFilled class="icon" />
              <TaobaoCircleFilled class="icon" />
              <WeiboCircleFilled class="icon" />
            </div>
          </div>
        </div>
      </div>
    </div>

    <div py-24px px-50px fixed bottom-0 z-11 w-screen text-14px>
      <GlobalLayoutFooter copyright="沈阳职场精英无线科技有限公司2025" icp="辽ICP备20009195号">
        <template #renderFooterLinks>
          <FooterLinks />
        </template>
      </GlobalLayoutFooter>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.login-container{
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: auto;
  background: var(--bg-color-container);
}

.login-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.login-main{
  box-shadow: var(--c-shadow);
}

.login-logo {
  width: 44px;
  height: 44px;
  margin-right: 16px;
  vertical-align: top
}
.login-title {
  color: var(--text-color);
  font-weight: 600;
  font-size: 33px;
  line-height: 1;
}

.login-desc {
  color: var(--text-color-1);
  font-size: 14px;
  margin-left: 16px
}

.login-main-right {
  .ant-tabs-nav-list {
    margin: 0 auto;
    font-size: 16px;
  }

  .login-other {
    line-height: 22px;
    text-align: center
  }

}

.icon {
  margin-left: 8px;
  color: var(--text-color-2);
  font-size: 24px;
  vertical-align: middle;
  cursor: pointer;
  transition: color .3s;

  &:hover {
    color: var(--pro-ant-color-primary);
  }
}

@mixin login-media($width: 100%) {
  .login-main {
    width: $width;
  }

  .login-main-left {
    display: none;
  }

  .login-main-right {
    width: 100%;
  }

  .login-desc {
    display: none;
  }
}

@media (min-width: 992px) {
  .login-main-left {
    width: 700px;
  }
}

@media (min-width: 768px) and (max-width: 991px) {
  .login-divider {
    display: none;
  }

  @include login-media(400px);
}

@media screen and (max-width: 767px) {
  @include login-media(350px);

  .login-divider {
    display: none;
  }
}
</style>
